/*
 *  server_main.cpp
 */

#include <iostream>
#include <string>
#include "../../common/src/debug.h"
#include "../../common/src/util.h"
#include "server_app.h"

static const int PARAM_LEN = 2;
static const int PARAM_PORT = 1;

static const int RUN_OK = 0;
static const int RUN_FAIL = -1;
static const int ERR_PARAM_LEN = 1;
static const int ERR_PORT = 2;

static const std::string MSG_PARAM_LEN("Cantidad de parametros incorrecta.");
static const std::string MSG_PORT("Puerto no valido.");

int main(int argc, char *argv[])
{
    if (argc != PARAM_LEN) {
        std::cerr << MSG_PARAM_LEN << std::endl;
        return ERR_PARAM_LEN;
    } else if (!Util::isnum(argv[PARAM_PORT])) {
        std::cerr << MSG_PORT << std::endl;
        return ERR_PORT;
    }

    int port = strtol(argv[PARAM_PORT], NULL, 0);

    try {
        ServerApp server(port);
        server.exec();
        return RUN_OK;
    } catch(...) {
        return RUN_FAIL;
    }
}

//{+}

